package com.线程案例.threadLocal;

/**
 * @author: LI-CI-GAO
 * 作者: licigao
 * 日期: 2021/8/16  15:27
 * 描述:
 */
public class MyThread extends Thread {

    private ThreadLocal<User11> threadLocal;

    public MyThread(ThreadLocal<User11> threadLocal,String name){
        super(name);
        this.threadLocal=threadLocal;
    }

    @Override
    public void run() {
        if(threadLocal.get()==null){
            threadLocal.set(new User11());
        }
        for (int i=0;i<3;i++){
            threadLocal.get().setUserName(Thread.currentThread().getName() + ":" + i);
            System.out.println("线程名称-》" + Thread.currentThread().getName() + "----"+i+"----" + threadLocal.get().getUserName());
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

}
